﻿package net.wangit.jdbc.database;

public class SQLServer extends Sybase {

	public SQLServer()
	{
	}

	public boolean bindLimitParametersFirst()
	{
		return super.bindLimitParametersFirst();
	}

	public String getLimitString(String querySelect, boolean hasOffset, int limit)
	{
		if (hasOffset)
			throw new UnsupportedOperationException("sql server has no offset");
		else
			return (new StringBuffer(querySelect.length() + 6)).append(querySelect).insert(getAfterSelectInsertPoint(querySelect), (new StringBuilder(" top ")).append(limit).toString()).toString();
	}

	public String appendIdentitySelectToInsert(String insertSQL)
	{
		return (new StringBuilder(String.valueOf(insertSQL))).append(" select SCOPE_IDENTITY()").toString();
	}

	public boolean supportsLimit()
	{
		return true;
	}

	public boolean useMaxForLimit()
	{
		return true;
	}

	public boolean supportsLimitOffset()
	{
		return false;
	}

	public boolean supportsVariableLimit()
	{
		return false;
	}

	private static int getAfterSelectInsertPoint(String sql)
	{
		return sql.startsWith("select distinct") ? 15 : 6;
	}
}
